package com.itheima.health.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ParseDateUtils {
    private static SimpleDateFormat sdf = null;

    /**
     * 输入指定格式,和时间字符串
     * @param pattern 格式  yyyy-MM-dd
     * @param dateStr 时间字符串 2022-06-10
     * @return
     * @throws ParseException
     */

    public static Date parseDate(String pattern,String dateStr) throws ParseException {
        sdf = new SimpleDateFormat(pattern);
        return  sdf.parse(dateStr);
    }

    public static String formatDate(String pattern,Date date) throws ParseException {
        sdf = new SimpleDateFormat(pattern);
        return  sdf.format(date);
    }
}
